﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SyndicateDAO.Classes;
using SyndicateDAO.DatabaseObject;

namespace SyndicateDAO.DAO
{
    public class UserDAO : DataBaseHelper<user>
    {
        public IQueryable<user> SelectAllBySyndicateId(int sId)
        {
            return this.SelectAll().Where(d => d.syndicateId == sId);
        }

        public IQueryable<user> SelectAllBySyndicateId(DataContext dc,int sId)
        {
            return this.SelectAll(dc).Where(d => d.syndicateId == sId);
        }

        public bool InsertUser(user d)
        {
            return this.Insert(d);
        }
        public bool UpdateUser()
        {
            return this.Update();
        }
        public bool DeleteUser(user d)
        {
            return this.Delete(d);
        }

        public user SelectSingleUser(int uId)
        {
            return this.SelectSingle(uId);
        }

        public user SelectSingleByEmailForCurrentSyndicate(string email,int syndicateId)
        {
            return this.SelectAll().SingleOrDefault(u => u.email.ToLower() == email.ToLower() && u.isEnabled && u.syndicateId == syndicateId);
        }


        public user SelectSingleByEmail(string email)
        {
            return this.SelectAll().SingleOrDefault(u => u.email.ToLower() == email.ToLower() && u.isEnabled);
        }

        public user SelectByEmailAndPassword(string email, string encodedPassword)
        {
            return this.SelectAll().SingleOrDefault(u => u.email.ToLower() == email.ToLower() && u.password == encodedPassword && u.isEnabled);
        }

        public user SelectByEmailAndPasswordForCurrentSyndicate(string email, string encodedPassword,int syndicateId)
        {
            return this.SelectAll().SingleOrDefault(u => u.email.ToLower() == email.ToLower() && u.password == encodedPassword && u.isEnabled && u.syndicateId == syndicateId);
        }
    }
}
